package com.eesujie.catimor.context;

import com.eesujie.catimor.exception.NonUniqueBindingException;
import org.jetbrains.annotations.NotNull;

import java.util.HashMap;
import java.util.Map;

public abstract class InjectorConfig {
    final Map<Class<?>, Class<?>> typeBinder = new HashMap<>();
    abstract protected void config();

    protected <T> void bind(@NotNull Class<T> baseType, @NotNull Class<? extends T> derivedType) {
        if (typeBinder.containsKey(baseType)) {
            throw new NonUniqueBindingException(
                    String.format("baseClass: %s has been bound by derivedClass: %s",
                            baseType.getName(), typeBinder.get(baseType).getName())
            );
        }
        typeBinder.put(baseType, derivedType);
    }

}
